import type { ConsultType } from '@/enums'
import type { PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'
export default defineStore(
  'cp-consult',
  () => {
    const consult = ref<PartialConsult>({})
    // 记录问诊类型
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 记录问诊的医院级别
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 记录问诊科室id
    const setDepId = (id: string) => {
      consult.value.depId = id
    }
    // 记录问诊病情描述信息 四个字段
    const setIllnessInfo = (form: PartialConsult) => {
      const { illnessDesc, illnessTime, consultFlag, pictures } = form
      consult.value.illnessDesc = illnessDesc
      consult.value.illnessTime = illnessTime
      consult.value.consultFlag = consultFlag
      consult.value.pictures = pictures
    }
    // 记录问诊的患者id
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }
    // 设置优惠券的id
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }
    // 清空consult
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllnessInfo,
      setPatientId,
      setCouponId,
      clear
    }
  },
  { persist: true }
)
